import { Body, Controller, Get, Inject, Post, Query } from '@midwayjs/core';
import { UserService } from '../service/user.service';
import { BaseController } from './base.controller';
import { LoginDTO } from '../dto/login';
import { PREFIX } from '../contanst';

@Controller(PREFIX)
export class OpenController extends BaseController {
  @Inject()
  userService: UserService;

  @Post('/open/user')
  async add(@Body() data: LoginDTO) {
    const res = await this.userService.add(data);
    return this.success(res);
  }

  @Get('/user')
  async info() {
    const user = await this.userService.info();
    return this.success(user);
  }

  @Get('/users')
  async index(@Query('size') size = 10, @Query('page') page = 1) {
    const user = await this.userService.page({ data: { page, size } });
    return this.success(user);
  }
}
